package com.greendragon.service.frontend.impl; 

import java.util.List;

import com.greendragon.persistence.dao.IBaseDao;
import com.greendragon.persistence.enmu.FetchOrderType;
import com.greendragon.persistence.enmu.LockType;
import com.greendragon.service.frontend.IBaseFrontendService;

/** 
 * @author wulibin, exceptsky@gmail.com, 2011-11-7 下午09:12:34
 * 
 */
public class BaseFrontendService<T> implements IBaseFrontendService<T>{
	protected IBaseDao<T> dao;
	protected int pageLength = 15;
	
	@Override
	public T get(Long id) {
		return dao.get(id);
	}

	@Override
	public List<T> getAll() {
		return dao.getAll(FetchOrderType.CREATE_DESC);
	}

	@Override
	public List<T> getByCondition(T expEntity, int page) {
		return dao.getByCondition(expEntity, page*pageLength, pageLength, FetchOrderType.CREATE_DESC);
	}

	@Override
	public long getCountByCondition(T expEntity) {
		return dao.getCountByCondition(expEntity);
	}

	@Override
	public List<T> getPage(int page) {
		return dao.getPage(page * pageLength, pageLength, LockType.UNLOCK, FetchOrderType.CREATE_DESC);
	}

	@Override
	public long getTotalCount() {
		return dao.getTotalCount(LockType.UNLOCK);
	}
	
	@Override
	public void setPageLength(int length){
		this.pageLength = length;
	}
	
	@Override
	public int getPageLength(){
		return this.pageLength;
	}
	
	public void setDao(IBaseDao<T> dao) {
		this.dao = dao;
	}

}
 